<?php
/**
 * Api to tag a contact as important for a company
 * 
 * 
 */

use Hive\Ressource\Experience;
$xview = Xview::instance();
$rid = $xview->val('rid');
$expid = $xview->val('expid');

if(!empty($expid) && !empty($rid)) {
	try  {
		$experience = \Fox\Dao::load(Experience::className(),$expid.':'.$rid);
		$oldimportance = $experience->importance;
		if(empty($oldimportance)) {
			$experience->importance = 1;
		} else {
			$experience->importance = 0;
		}
		
		$experience->update();
		if($experience->importance == 1) {
			Fox\Message::Success(Msg(Hive::BUNDLE,Hive::CONTACT_HAS_BEEN_MARKED_AS_VIP));
		} else {
			Fox\Message::Success(Msg(Hive::BUNDLE,Hive::CONTACT_IS_NOT_VIP_ANYMORE));
		}
	} catch(Fox\Object\Exception\Save $e) {
		Fox\Message::Error($e);
	} catch(Fox\Object\Exception\NotExist $e) {
		Fox\Message::Error($e);
	}
} else {
	// @TODO add an error message
}
return $xview->messages(true,true);